<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit|ie-comp|ie-stand" />
		<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
		<title>课堂任务提交情况-精准微课堂</title>
		<%@ include file="/common/commonLib.jsp"%>
		<link rel="stylesheet" type="text/css" href="<c:url value='/css/classroomIndex.css'/>" />
		<link rel="stylesheet" type="text/css" href="<c:url value='/css/common-main.css'/>"/>
		<script src="<c:url value='/js/classroomIndex.js'/>" type="text/javascript" charset="utf-8"></script>
	</head>

	<body>
		
		<div class="container-fluid main">
			<%@include file="/common/header.jsp"%>
			<%@include file="common/classroomHeader.jsp"%>
			
			<div class="row classroom-index-con">
			
				<div class="col-md-12 col-lg-12">
				
					<div class="classroom-index-con-content">
						<div class="row">
							<div class="col-md-1"></div>
							<div class="col-md-10">
								<%@include file="common/classroomNav.jsp"%>
							</div>
							
							<div class="col-md-1"></div>
						</div>
						<div class="row">
							<div class="col-md-1"></div>
							<div class="col-md-10">
								<div class="tab-nav">
									<a id="href1" style="font-weight: 700;font-size: 1.6rem;color:#3b92dc;">任务首页
									</a>&nbsp;>&nbsp;<span id="href2" style="font-weight: 700;font-size: 1.6rem;color:#00b43c;"></span>
								</div>
							</div>
							<div class="col-md-1"></div>
						</div>
						<div class="row">
							<!-- 课堂任务 -->
							<div class="classroom-task">
								<div class="col-md-1"></div>
								<div class="col-md-10">
									<hr>
									<!-- 任务名 -->
									<div class="form-group">
										<label for="">任务名称</label>
										<span id="title"></span>
										<span id="type"></span>
									</div>
									<hr>
									<!--任务描述 -->
									<div class="row">
										<div class="col-md-12">
											<label for="">任务描述</label>
										</div>
										<div class="col-md-12">
											<div id="description"></div>
										</div>
									</div>
									<hr>
									<!--任务附件 -->
									<div class="row">
										<div class="col-md-12">
											<label for="">任务附件</label>
										</div>
										<div class="col-md-12">
											<ul id="task-file-list-edit">
															
											</ul>
										</div>
									</div>
									<hr>
									<!--标准答案-->
									<div class="row">
										<div class="col-md-12">
											<label for="">标准答案</label>
										</div>
										<div class="col-md-12">
											<div id="standardAnswer"></div>
										</div>
									</div>
									<hr>
									<!--标准答案附件 -->
									<div class="row">
										<div class="col-md-12">
											<label for="">标准答案附件</label>
										</div>
										<div class="col-md-12">
											<ul id="answer-file-list-edit">
												
											</ul>
										</div>
									</div>
								</div>
								<div class="col-md-1"></div>
							</div>
						</div>
						
						<div class="row" style="margin-top:2rem;">
							<div class="col-md-4"></div>
							<div class="col-md-4" style="text-align: center;">
								<input type="button" id="publish-now-btn" value="立即发布" class="btn btn-primary" />
								<input type="button" id="cancel-now-btn" value="取消发布" class="btn btn-success" />
								<input type="button" id="publish-answer-btn" value="公布答案" class="btn btn-primary" />
								<input type="button" id="cancel-answer-btn" value="取消答案公布" class="btn btn-success" />
							</div>
							<div class="col-md-4"></div>
						</div>
					</div>
					
				</div>
			</div>
			
			
			<div class="row" id="classroom-task-personal">
				<div class="col-md-1"></div>
				<div class="col-md-10">
					<table class="table table-hover">
						<thead>
							<tr>
								<th>学号</th>
								<th>姓名</th>
								<th>分数</th>
								<th>状态/操作</th>
							</tr>
						</thead>
						<tbody id="taskInLessonAssignList">
							
						</tbody>
					</table>
				</div>
				<div class="col-md-1"></div>
			</div>
	
	
			<div class="row" id="classroom-task-all">
				<div class="col-md-1"></div>
				<div class="col-md-10">
					<table class="table table-hover">
						<thead>
							<tr>
								<th>学号</th>
								<th>提交者</th>
								<th>提交时间</th>
								<th>待批阅者</th>
								<th>共享状态</th>
								<th>
									<select class="form-control" id="submitStatus" onchange="searchTaskStatus()" >
										<option value="ALL">全部</option>
										<option value="UNCOMMITTED">未提交</option>
										<option value="COMMITTED">已提交</option>
										<option value="HAVEREAD">已批阅</option>
									</select>
								</th>
							</tr>
						</thead>
						<tbody id="submitList">
							
						</tbody>
					</table>
				</div>
				<div class="col-md-1"></div>
			</div>
			
		</div>
		
		<%@include file="/common/footer.jsp"%>
	</body>
<script>
var data=${data};
var pageNo = 1;
$(document).ready(function(){
	if (data.status != "success"){
		alert(data.message);
		return;
	}
	$("#classroom-href-task").css("color","#00b43c");
	$("#href1").attr("href",CONTEXT_PATH + "lessonTaskView/tlview?lessonId=" + data.data.view.lessonId);
	$("#href2").text(isNull(data.data.view.title));
	
	initLesson(data.data.view.lessonId);//初始化课堂信息
	initPage();
	changeLessonUrl(data.data.view.lessonId);//初始化导航链接
	$("#cancel-now-btn").hide();
	$("#cancel-answer-btn").hide();
	if(data.data.view.isVisible == "YES") {
		$("#publish-now-btn").hide();
		$("#cancel-now-btn").show();
		$("#cancel-now-btn").click(function() {
			cancelShowVisible();
			cancelShowAnswerVisible();
		});
		if(data.data.view.isAnswerVisible=="YES"){
			$("#publish-answer-btn").hide();
			$("#cancel-answer-btn").show();
			$("#cancel-answer-btn").click(cancelShowAnswerVisible);
		}else{
			$("#publish-answer-btn").show();
			$("#publish-answer-btn").click(showAnswerVisible);
		}
	} else {
		$("#publish-now-btn").show();
		$("#publish-answer-btn").hide();
		$("#classroom-task-all").hide();
		$("#publish-now-btn").click(showVisible);
		$("#taskInLessonAssignList td .btn").attr("disabled","disabled");
	};
	
});

var initPage  = function(){
	initTaskDetail();
	initFileList(data.data.view.attachment.files,"attach");
	initFileList(data.data.view.answerAttachment.files,"answerAttach");

	if(data.data.view.type=="TESTINLESSON"||data.data.view.type=="HOMEWORK"||data.data.view.type=="LABTEST"){
		initTaskMianList(data.data);
		$("#classroom-task-all").show();
		$("#classroom-task-personal").hide();
	} else {
		initTaskInLessonList(data.data.view.scorePerforms);
		$("#classroom-task-personal").show();
		$("#classroom-task-all").hide();
	}
	
}

var getType=function(type){
	var taskType="";
	if(type=="ASKINLESSON"){
		taskType="课堂提问";
	}else if(type=="TESTINLESSON"){
		taskType="当堂测试";
	}else if(type=="HOMEWORK"){
		taskType="课后作业";
	}else if(type=="LABTEST"){
		taskType="实验任务";
	}
	return taskType;
}
var isNull = function(string){
	if(string == null || string.trim() == "" || string.trim() == "<p><br></p>"){
		return "(无)";
	}else{
		return string.trim();	
	}	
}
var initTaskDetail=function(){
	$("#title").text(isNull(data.data.view.title));
	$("#type").text("(类型："+getType(data.data.type)+")");
	$("#description").html(isNull(data.data.view.description));
	$("#standardAnswer").html(isNull(data.data.view.standardAnswer));		
}
var initFileList =function(list,attachType){
	var obj=null;
	if(attachType=="attach"){
		obj=$("#task-file-list-edit");
	}else{
		obj=$("#answer-file-list-edit");
	}
	obj.empty();
	if(list.length <= 0){
		var temp = "<li><span>无附件</span></li>";
		obj.append(temp);
	}else{
		for(var i=0;i<list.length;i++){
			var temp = "";
			temp += ("<li>");
			temp += ("<span  title=\""+list[i].name+"\">" + list[i].name + "</span>");
			temp += ("<a href=\"<c:url value='/resource/download/"+list[i].url+"'/>\">下载</a>");
			temp += ("</li>");
			obj.append(temp);
		}
	}
	
}
var initTaskMianList= function(data){
	var submitList=$("#submitList");
	submitList.empty();
	var list =data.list;
	if(list.length <= 0){
		var s="<tr><td colspan=\"6\">无记录</td></tr>";
		submitList.append(s);
	}else {
		for(var i=0;i<list.length;i++){
			var item=list[i];
			var s="";
			if(item.status=="UNCOMMITTED"){
				s+="<tr onclick=\"wrong()\">";
				s+="<td title=\""+item.ucode+"\">"+item.ucode+"</td>";
				s+="<td title=\""+item.assignedName+"\">"+item.assignedName+"</td>";
				s+="<td>---</td>";
				s+="<td title=\""+item.reviewName+"\">"+item.reviewName+"</td>";
				s+="<td>---</td>";
				s+="<td title=\"未提交\">未提交</td>";
			}else if(item.status=="COMMITTED"){
				s+="<tr onclick=\"initSubmitDetail("+item.id+")\">";
				s+="<td title=\""+item.ucode+"\">"+item.ucode+"</td>";
				s+="<td title=\""+item.assignedName+"\">"+item.assignedName+"</td>";
				s+="<td title=\""+item.uploadTime+"\">"+item.uploadTime+"</td>";
				s+="<td title=\""+item.reviewName+"\">"+item.reviewName+"</td>";
				s+="<td>---</td>";
				s+="<td title=\"已提交\">已提交</td>";
			}else{
				s+="<tr onclick=\"initSubmitDetail("+item.id+")\">";
				s+="<td title=\""+item.ucode+"\">"+item.ucode+"</td>";
				s+="<td title=\""+item.assignedName+"\">"+item.assignedName+"</td>";
				s+="<td title=\""+item.uploadTime+"\">"+item.uploadTime+"</td>";
				s+="<td title=\""+item.reviewName+"\">"+item.reviewName+"</td>";
				if(item.isShare=="YES"){
					//注：数据属性中没有获取 isShare参数
					s+="<td title=\"已共享\">已共享</td>";
				}else{
					s+="<td title=\"未共享\">未共享</td>";
				}
				s+="<td title=\"已批阅\">已批阅</td>";
			}			
			s+="</tr>"
			submitList.append(s);
		}
	}
}
var initSubmitDetail = function(id) {
	window.location.href = CONTEXT_PATH + "taskSubmitResult/detail?id=" + id;
}
var wrong = function() {
	alert("该学生未提交任务！\n"+"如果需要评分，请到'课程->任务->任务提交记录'页面点击'更改提交状态'按钮，再进行评分");
}
var initTaskInLessonList= function(list){
	var assignList=$("#taskInLessonAssignList");
	assignList.empty();
	for(var i=0;i<list.length;i++){
		var s="<tr>";
		s+="<td title=\""+list[i].ucode+"\">"+list[i].ucode+"</td>";
		s+="<td title=\""+list[i].askStuName+"\">"+list[i].askStuName+"</td>";
		if(list[i].isScore=="YES"){
			s+="<td class=\"score-edit\">"+list[i].mark+"</td>";
			s+="<td class=\"score-edit-btn"+i+"\"><span onclick=\"editScore("+i+","+list[i].id+",this)\">编辑</span></td>";
		}else{
			s+="<td class=\"score-td\"><input type=\"number\" class=\"form-control score\" value=\"\"></td>";
			s+="<td><span onclick=\"scorePerformance("+list[i].id+",this)\">评分</span></td>";
		}
		s+="</tr>";
		assignList.append(s);
	}
}
var editScore = function(i,id,obj) {
	$(obj).parent(".score-edit-btn"+i).empty();
	$(".score-edit-btn"+i).append("<span onclick=\"scorePerformanceEdit("+i+","+id+")\">评分</span>");
	var score1 = $(".score-edit-btn"+i).siblings(".score-edit").text();
	$(".score-edit-btn"+i).siblings(".score-edit").empty();
	$(".score-edit-btn"+i).siblings(".score-edit").append("<input type=\"number\" class=\"form-control score\" value=\""+score1+"\">");
	
}
var scorePerformance = function(id,obj){
	var score=$(obj).parent("td").siblings(".score-td").children("input").val();
	var json={//获取要评分的学生成绩
			id:id,
			mark:score
	};
	$.post(CONTEXT_PATH+"scorePerformance/scorePerform", {
		data : JSON.stringify(json)
	}, function(data) {
		if(data.status=="success"){
			$(obj).attr("disabled","disabled");
			$(obj).val("已评分");
			window.location.reload();
		}else{
			alert(data.message);
			
		}
	});
}
var scorePerformanceEdit = function(i,id){
	var score=$(".score-edit-btn"+i).siblings(".score-edit").children("input").val();
	var json={//获取要评分的学生成绩
			id:id,
			mark:score
	};
	$.post(CONTEXT_PATH+"scorePerformance/scorePerform", {
		data : JSON.stringify(json)
	}, function(data) {
		if(data.status=="success"){
			window.location.reload();
		}else{
			alert(data.message);
			
		}
	});
}
var showAnswerVisible = function(){
	var json={
			id:data.data.view.id,
		    isVisible:"YES"	
		};
		$.post(CONTEXT_PATH+"taskAssignment/ajaxUpdateAnswer", {
			data : JSON.stringify(json)
		}, function(data) {
			if(data.status=="success"){
				window.location.reload();
			}else{
				alert(data.message);
			}
		});
}

var cancelShowAnswerVisible = function(){
	var json={
			id:data.data.view.id,
		    isVisible:"NO"	
		};
		$.post(CONTEXT_PATH+"taskAssignment/ajaxUpdateAnswer", {
			data : JSON.stringify(json)
		}, function(data) {
			if(data.status=="success"){
				window.location.reload();
			}else{
				alert(data.message);
			}
		});
}
var showVisible = function(){
	var json={
		id:data.data.view.id,
	    isVisible:"YES"	
	};
	$.post(CONTEXT_PATH+"taskAssignment/ajaxUpdateVisible", {
		data : JSON.stringify(json)
	}, function(data) {
		if(data.status=="success"){
			window.location.reload();
		}else{
			alert(data.message);
		}
	});
}

var cancelShowVisible = function(){
	var json={
		id:data.data.view.id,
	    isVisible:"NO"	
	};
	$.post(CONTEXT_PATH+"taskAssignment/ajaxUpdateVisible", {
		data : JSON.stringify(json)
	}, function(data) {
		if(data.status=="success"){
			window.location.reload();
		}else{
			alert(data.message);
		}
	});
}

var searchTaskStatus = function(){
	var json={
			assignId:data.data.view.id
	}
	var submitStatus=$("#submitStatus  option:selected").val();
	if(submitStatus=="ALL"){
		
	} else if(submitStatus=="UNCOMMITTED"){
		json.status = "UNCOMMITTED";
	} else if(submitStatus=="COMMITTED"){
		json.status = "COMMITTED";
	} else if(submitStatus=="HAVEREAD"){
		json.status = "HAVEREAD";
	}
	fetchSubmitList(json);
}

var fetchSubmitList = function(json){
	$.post(CONTEXT_PATH+"lessonTaskMainDetail/submitList", {
		data : JSON.stringify(json)
	}, function(data) {
		if(data.status=="success"){
			initTaskMianList(data.data);
		}else{
			alert(data.message);
		}
	});
};

var isEmpty=function(s){
	if(s==null||s=="" || s==undefined){
		return true;
	}
	return false;
};
</script>
</html>